package utils.global.Interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import utils.global.UtilsConfig;

@ConditionalOnBean(TokenInterceptorConfig.class)
@Configuration
@Slf4j
public class TokenInterceptorUtils implements WebMvcConfigurer {

    public TokenInterceptorUtils() {
        log.info(String.format(UtilsConfig.printInfo, "tokenInterceptor"));
    }

    @Autowired
    TokenInterceptorConfig interceptorConfig;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(interceptorConfig).addPathPatterns("/**")
                .excludePathPatterns(interceptorConfig.excludePaths);
    }
}
